/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.alipay.study.comsumer.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.alipay.study.comsumer.service.user.UserServiceI;

/**
 * 
 * @author wb-qlj205528
 * @version $Id: UserController.java, v 0.1 2016年11月16日 下午4:53:10 wb-qlj205528 Exp $
 */
@RestController
@RequestMapping(value = "/user", method = { RequestMethod.GET, RequestMethod.POST })
public class UserController {

    /**
     * 
     */
    @Autowired
    private UserServiceI userService;

    /**
     * 
     */
    @Autowired
    RestTemplate         restTemplate;

    /**
     * 
     * 通过Feign代理的接口 UserServiceI 访问Eureka客户端提供的服务
     * @return
     */
    @RequestMapping("/getuser")
    public Map<String, String> getUserFeign() {
        return userService.getUser();
    }

    /**
     * 
     * 通过Ribbon请求url访问Eureka客户端提供的服务
     * @return
     */
    public Map<String, String> getUserRibbon() {
        Map<String, String> map = new HashMap<String, String>();
        //访问的url为 服务提供者的serviceId（appName）+url(RequestMapping)
        map = restTemplate.getForEntity("http://service-provider/getuser", map.getClass())
            .getBody();
        return map;
    }
}
